package com.jhgsys.internal.peccancy.controller.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jhgsys.internal.common.constant.DictCodeConstant;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.dict.service.IDictService;
import com.jhgsys.internal.peccancy.entity.PeccancyClause;
import com.jhgsys.internal.peccancy.entity.PeccancyClauseRule;
import com.jhgsys.internal.peccancy.service.IPeccancyClauseRuleService;
import com.jhgsys.internal.peccancy.service.IPeccancyClauseService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Slf4j
@Validated
@Controller
public class CommonPeccancyClauseController extends BaseController {

    @Autowired
    private IPeccancyClauseService peccancyClauseService;

    @Autowired
    private IPeccancyClauseRuleService peccancyClauseRuleService;

    @Autowired
    private IDictService dictService;


    @GetMapping(FebsConstant.VIEW_PREFIX + "common/peccancyClause")
    public String commonPeccancyClause(Model model){
        model.addAttribute("disposeFormList", dictService.findDictByCode(DictCodeConstant.SAFETY_PECCANCY_DISPOSE_FORM));
        return FebsUtil.view("common/peccancyClauseCommon");
    }

    /**
     * 查询（分页）
     * @author admin
     * @date 2024-08-08 13:20:26
     */
    @GetMapping("common/peccancyClause/list")
    @ResponseBody
    public FebsResponse peccancyClauseList(QueryRequest request, PeccancyClause peccancyClause) {
        if(StringUtils.isBlank(peccancyClause.getTenantId())){
            peccancyClause.setTenantId(getCurrentTenantId());
        }
        IPage<PeccancyClause> peccancyClausePage = peccancyClauseService.findPeccancyClausePage(request, peccancyClause);
        Map<String, Object> dataTable = getDataTable(peccancyClausePage);
        return new FebsResponse().success().data(dataTable);
    }

    /**
     * 查询（分页）
     * @author admin
     * @date 2024-08-08 13:20:26
     */
    @GetMapping("common/peccancyClauseRule/list")
    @ResponseBody
    public FebsResponse peccancyClauseRuleList(PeccancyClauseRule peccancyClauseRule, QueryRequest request) {
        if(StringUtils.isBlank(peccancyClauseRule.getTenantId())){
            peccancyClauseRule.setTenantId(getCurrentTenantId());
        }
        IPage<PeccancyClauseRule> peccancyClauseRulePage = peccancyClauseRuleService.findPeccancyClauseRulePage(request, peccancyClauseRule);
        Map<String, Object> dataTable = getDataTable(peccancyClauseRulePage);
        return new FebsResponse().success().data(dataTable);
    }


}
